package com.itheima.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.Account;
import com.itheima.exception.BusinessException;
import com.itheima.service.AccountService;
import com.itheima.vo.Code;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author xiangjun.deng
 * email 17670934918dxj@sina.com
 * @date 2021/8/20 15:05
 * @desc
 */
@RestController
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private AccountService accountService;
    @RequestMapping("/save")
    public void save(@RequestBody Account account) throws IOException {
        accountService.save(account);

    }

    @GetMapping("/{page}/{size}")
    public Result getAll(@PathVariable Integer page, @PathVariable Integer size){
        PageInfo<Account> all = accountService.findAll(page, size);
        return new Result(null != all ? Code.GET_OK: Code.GET_ERROR,all.getList());
    }

}
